package com.hiray.restcache.helper

import android.content.Context
import android.content.SharedPreferences

open class Helper : ContextProvider() {

    val TAG = "Helper"


    override fun onContextInit(context: Context) {
        app = context
    }


    companion object R {

        lateinit var app: Context

        val editor: SharedPreferences.Editor by lazy {
            app.getSharedPreferences(
                "DATA",
                Context.MODE_PRIVATE
            ).edit()
        }

        val pref: SharedPreferences by lazy {
            app.getSharedPreferences(
                "DATA",
                Context.MODE_PRIVATE
            )
        }

        fun put(key: String, value: String) {

            editor.putString(key, value)
                .commit()

        }

        fun get(key: String, default: String) = pref.getString(key, default)


        fun token(token: String) = put("key_token", token)

        fun token() = get("key_token", "")?:""
    }


}